#include <bits/stdc++.h>
// 2025/02/05
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, dp[59][262145];

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++){
        int t;
        cin >> t;
        dp[t][i] = i + 1;
    }
    int ans = 0;
    for (int i = 1; i <= 58; i++)
        for (int j = 1; j <= n; j++){
            if (dp[i][j] == 0)
                dp[i][j] = dp[i - 1][dp[i - 1][j]];
            if (dp[i][j] != 0)
                ans = i;
        }
    cout << ans;
    return 0;
}